﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JGSY.WinAlarmManage
{
    /// <summary>
    /// 封装一个安全的 Invoke扩展
    /// </summary>
    public static class ControlExtensions
    {
        /// <summary>
        /// 封装一个安全的 Invoke 
        /// </summary>
        /// <param name="control"></param>
        /// <param name="action"></param>
        public static void SafeInvoke(this Control control, Action action)
        {
            if (control.IsDisposed || !control.IsHandleCreated)
                return;

            if (control.InvokeRequired)
            {
                control.Invoke(action);
            }
            else
            {
                action();
            }
        }
    } 
}
